﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VM.Core;
using VM.PlatformSDKCS;
using IMVSCircleFindModuCs;

namespace Vision.page
{
    public partial class CircleFindControl : UserControl
    {
        IMVSCircleFindModuTool iMVSCircleFindModuTool;
        public CircleFindControl()
        {
            InitializeComponent();
        }

        public CircleFindControl(string FeatureModuleName)
        {
            InitializeComponent();
            comboBox1.Items.Clear();
            comboBox1.Items.Add("最强");
            comboBox1.Items.Add("最后一条");
            comboBox1.Items.Add("第一条");
            comboBox2.Items.Clear();
            comboBox2.Items.Add("从黑到白");
            comboBox2.Items.Add("从白到黑");
            comboBox2.Items.Add("任意极性");
            iMVSCircleFindModuTool = (IMVSCircleFindModuTool)VmSolution.Instance[FeatureModuleName];
            textBox1.Text = iMVSCircleFindModuTool.ModuParams.MinRadius.ToString();
            textBox2.Text = iMVSCircleFindModuTool.ModuParams.MaxRadius.ToString();

            
            if (iMVSCircleFindModuTool.ModuParams.FindMode == IMVSCircleFindModuCs.CircleFindParam.FindModeEnum.Best)
            {
                comboBox1.Text = "最强";
            }
            else if (iMVSCircleFindModuTool.ModuParams.FindMode == IMVSCircleFindModuCs.CircleFindParam.FindModeEnum.Largest)
            {
                comboBox1.Text = "最后一条";
            }
            else if (iMVSCircleFindModuTool.ModuParams.FindMode == IMVSCircleFindModuCs.CircleFindParam.FindModeEnum.SMALLEST)
            {
                comboBox1.Text = "第一条";
            }

            if (iMVSCircleFindModuTool.ModuParams.EdgePolarity.ToString() == "BlackToWhite")
            {
                comboBox2.Text = "从黑到白";
            }
            else if(iMVSCircleFindModuTool.ModuParams.EdgePolarity.ToString() == "WhiteToBlack")
            {
                comboBox2.Text = "从白到黑";
            }
            else if(iMVSCircleFindModuTool.ModuParams.EdgePolarity.ToString() == "Both")
            {
                comboBox2.Text = "任意极性";
            }
            textBox3.Text = iMVSCircleFindModuTool.ModuParams.EdgeThresh.ToString();
            textBox4.Text = iMVSCircleFindModuTool.ModuParams.EdgeWidth.ToString();
            textBox5.Text = iMVSCircleFindModuTool.ModuParams.RadNum.ToString();
            textBox6.Text = iMVSCircleFindModuTool.ModuParams.RejectNum.ToString();

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text != "")
                {
                    iMVSCircleFindModuTool.ModuParams.MinRadius = Convert.ToInt32(textBox1.Text);
                }

            }
            catch (VmException ex)
            {
                string strMsg = ex.errorMessage + "ErrorCode is " + ex.errorCode.ToString();
            }
            catch (Exception ex)
            {
                string strMsg = Convert.ToString(ex);
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (textBox2.Text != "")
                {
                    iMVSCircleFindModuTool.ModuParams.MaxRadius = Convert.ToInt32(textBox2.Text);
                }

            }
            catch (VmException ex)
            {
                string strMsg = ex.errorMessage + "ErrorCode is " + ex.errorCode.ToString();
            }
            catch (Exception ex)
            {
                string strMsg = Convert.ToString(ex);
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (comboBox1.Text == "最强")
                {
                    iMVSCircleFindModuTool.ModuParams.FindMode = IMVSCircleFindModuCs.CircleFindParam.FindModeEnum.Best;
                }
                else if (comboBox1.Text == "最后一条")
                {
                    iMVSCircleFindModuTool.ModuParams.FindMode = IMVSCircleFindModuCs.CircleFindParam.FindModeEnum.Largest;
                }
                else if (comboBox1.Text == "第一条")
                {
                    iMVSCircleFindModuTool.ModuParams.FindMode = IMVSCircleFindModuCs.CircleFindParam.FindModeEnum.SMALLEST;
                }
            }
            catch (VmException ex)
            {
                string strMsg = ex.errorMessage + "ErrorCode is " + ex.errorCode.ToString();
            }
            catch (Exception ex)
            {
                string strMsg = Convert.ToString(ex);
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (comboBox2.Text == "从黑到白")
                {
                    iMVSCircleFindModuTool.ModuParams.EdgePolarity = IMVSCircleFindModuCs.CircleFindParam.EdgePolarityEnum.BlackToWhite;
                }
                else if (comboBox2.Text == "从白到黑")
                {
                    iMVSCircleFindModuTool.ModuParams.EdgePolarity = IMVSCircleFindModuCs.CircleFindParam.EdgePolarityEnum.WhiteToBlack;
                }
                else if (comboBox2.Text == "任意极性")
                {
                    iMVSCircleFindModuTool.ModuParams.EdgePolarity = IMVSCircleFindModuCs.CircleFindParam.EdgePolarityEnum.Both;
                }
            }
            catch (VmException ex)
            {
                string strMsg = ex.errorMessage + "ErrorCode is " + ex.errorCode.ToString();
            }
            catch (Exception ex)
            {
                string strMsg = Convert.ToString(ex);
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (textBox3.Text != "")
                {
                    iMVSCircleFindModuTool.ModuParams.EdgeThresh = Convert.ToInt32(textBox3.Text);
                }

            }
            catch (VmException ex)
            {
                string strMsg = ex.errorMessage + "ErrorCode is " + ex.errorCode.ToString();
            }
            catch (Exception ex)
            {
                string strMsg = Convert.ToString(ex);
            }
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (textBox4.Text != "")
                {
                    iMVSCircleFindModuTool.ModuParams.EdgeWidth = Convert.ToInt32(textBox4.Text);
                }

            }
            catch (VmException ex)
            {
                string strMsg = ex.errorMessage + "ErrorCode is " + ex.errorCode.ToString();
            }
            catch (Exception ex)
            {
                string strMsg = Convert.ToString(ex);
            }
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (textBox5.Text != "")
                {
                    iMVSCircleFindModuTool.ModuParams.RadNum = Convert.ToInt32(textBox5.Text);
                }

            }
            catch (VmException ex)
            {
                string strMsg = ex.errorMessage + "ErrorCode is " + ex.errorCode.ToString();
            }
            catch (Exception ex)
            {
                string strMsg = Convert.ToString(ex);
            }
        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (textBox6.Text != "")
                {
                    iMVSCircleFindModuTool.ModuParams.RejectNum = Convert.ToInt32(textBox6.Text);
                }

            }
            catch (VmException ex)
            {
                string strMsg = ex.errorMessage + "ErrorCode is " + ex.errorCode.ToString();
            }
            catch (Exception ex)
            {
                string strMsg = Convert.ToString(ex);
            }
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
